package main

import (
	"net"
	"github.com/name5566/leaf/log"
	"wind/wind-config"
)

func main() {
	wind_config.ConfigServer("wind-config/server.json")

	srcAddr := &net.UDPAddr{IP: net.IPv4zero, Port: 0}
	dstAddr := &net.UDPAddr{IP: net.ParseIP(wind_config.ServerConfig.ServerHost), Port: wind_config.ServerConfig.ServerPort}

	conn, err := net.ListenUDP("udp", srcAddr)
	if err != nil {
		log.Fatal("%s", err)
	}

	n, err := conn.WriteToUDP([]byte("hello"), dstAddr)
	if err != nil {
		log.Fatal("%s", err)
	}

	data := make([]byte, 1024)
	for {
		n, _, err = conn.ReadFrom(data)
		if err != nil {
			log.Fatal("%s", err)
		}
		log.Debug("read %s from <%s>\n", data[:n], conn.RemoteAddr())
	}
}
